/*
 * обход в глубину (DFS)
 */

int comp[NMAX];

int
main(void)
{
	int comp_number = 0;
	int i = 0;

	memset(comp, 0, sizeof(comp));

	for (; i < n ; ++i) {
		if (comp[i] == 0) {
			++comp_number;
			dfs(i, comp_number);
		}
	}
}

void
dfs(int u, int comp_number)
{
	comp[u] = comp_number;

	for /* v, (u,v) edge exists */
		if (comp[v] == 0)
			dfs(v, comp_number);
}

void
dfs_(int u)
{
	color[u] = GREY;
	++time;
	in_time[u] = time;
	for /* v ; (u,v) in E */ {
		if (color[v] == WHITE) {
			parent[v] = u;
			dfs_(v);
		}
	}
	++time;
	out_time[u] = time;
	color[u] = BLACK;
}
